package com.lhkj.ct.meta.modules.patient.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lhkj.ct.base.enums.PatSourceEnum;
import com.lhkj.ct.meta.modules.patient.model.entity.TblPatSource;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 档案来源 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2023-12-15
 */
public interface TblPatSourceMapper extends BaseMapper<TblPatSource> {

    @Insert("insert ignore into tbl_pat_source " +
            "(id, pat_id, source_type, create_by, create_time)" +
            "select  #{id}, #{patId}, #{sourceType}, #{createBy}, #{createTime,jdbcType=TIMESTAMP} where exists " +
            "(select id from tbl_patient where id = #{patId,jdbcType=VARCHAR})")
    int insertOnDuplicate(TblPatSource patSource);


    @InterceptorIgnore
    List<Map<String, Object>> countBySourceType(@Param("patSources") PatSourceEnum[] patSources);
}
